import request from '../utils/request'

/**
 * 获取购物车商品总数
 */
export const getCartTotalAPI = () => {
  return request.get('/cart/total')
}

/**
 * 添加商品到购物车
 */
export const postCartAddAPI = (goodsId, goodsNum = 1) => {
  return request.post('/cart/add', {
    goodsId,
    goodsSkuId: '0',
    goodsNum,
  })
}

/**
 * 获取当前登录用户的购物车列表
 * @returns
 */
export const getCartListAPI = () => {
  return request.get('/cart/list')
}

/**
 *  删除购物车商品
 * @param {*} id 删除商品Id
 * @returns
 */
export const postCartClearByIdAPI = (id) => {
  return request.post('/cart/clear', {
    cartIds: [id],
  })
}

/**
 *  删除购物车商品
 * @param {*} id 删除商品Id
 * @returns
 */
export const postCartClearAPI = (cartIds) => {
  return request.post('/cart/clear', {
    cartIds,
  })
}

/**
 * 修改购物车商品数量
 * @param {*} goodsId
 * @param {*} goodsNum
 * @returns
 */
export const postCartUpdateAPI = (goodsId, goodsNum) => {
  return request.post('/cart/update', {
    goodsId,
    goodsSkuId: '0',
    goodsNum,
  })
}
